'use strict'

/*
|--------------------------------------------------------------------------
| Router
|--------------------------------------------------------------------------
|
| AdonisJs Router helps you in defining urls and their actions. It supports
| all major HTTP conventions to keep your routes file descriptive and
| clean.
|
| @example
| Route.get('/user', 'UserController.index')
| Route.post('/user', 'UserController.store')
| Route.resource('user', 'UserController')
*/

const Route = use('Route')

// Route.on('/').render('welcome')
Route.get('/',function * (request,response){
    response.send("Index Page")
});
// Route.get('/test',function * (request,response){
//   response.send('授权访问了')
// }).middleware('auth');

//SPA this's a bad idea
// Route.any('*', function * (request, response) {
//   yield response.sendView('home')
// })

//http://localhost:3333/users/123
// Route.get('/users/:id?',function * (request,response){
//   const id = request.param('id','暂时没有～');
//   response.send(`用户ID：${id}`);
// });

// 链接: `/~/media/xyz.pdf?download`
// Route.get('/*', function * (request, response) {
//   console.log('访问文件了!!!!!')
//   const media = request.param(0)
//
//   if (request.input('download') !== null) {
//     // ...
//   }
//
//   response.send(`哎~ 这个${media}文件, 送你了~`)
// })

//http://localhost:3333/demo/v1/users group
Route.group('version1', function () {
  Route.get('/users/:id?',function * (request,response){
    const id = request.param('id','暂时没有～');
    response.send(`用户ID：${id}`);
  });
}).prefix('demo/v1')

//资源路由 必须注册一个控制器
// Route
  // .resource('news','NewsController');
  // .addCollection('popular')这个方法在v4取消了
  // 详见 https://www.adonisjs.com/docs/4.0/upgrade-guide

  Route.get('news/popular/:id?', 'NewsController.getPopular')
  Route.resource('news', 'NewsController')
